<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
       <link rel="stylesheet" href="jgp/css/project/ui-color-v3.css">
    <link rel="stylesheet" href="jgp/css/project/ui-list-v3.css">
    <link rel="stylesheet" href="jgp/css/project/ui-input-v3.css">
    <link rel="stylesheet" href="jgp/css/project/ui-btn-v3.css">
    <link rel="stylesheet" href="jgp/css/project/ui-res-v3.css">
    <link rel="stylesheet" href="jgp/css/ui-color.css">
    <link rel="stylesheet" href="jgp/css/ui-res.css">
    <link rel="stylesheet" href="jgp/css/ui-input.css">
    <link rel="stylesheet" href="jgp/css/ui-base.css">
    <link rel="stylesheet" href="jgp/css/ui-box.css">
    <link rel="stylesheet" href="jgp/css/project/style.css">
	<link rel="stylesheet" href="jgp/css/my.css">
	
    <script src="js/zy_control.js"></script>
    <script src="js/zy_click.js"></script>
    <script src="js/zy_json.js"></script>
	<script src="jgp/js/common.js"></script>
    <script src="js/zy_event.js"></script>
	<script src="js/talkingdata.js"></script>
    </head>
    <body id="body" class="um-vp" ontouchstart>
        <!--块容器开始-->
        <div class="ub ub-ver t-wh ">
            <div class="ubb uinn uc-t1 ">
                <div class="ub uba c-wh uc-a1 b-gra us-i uinput uitextarealzz ub-ver uinn1-lzz ">
                    <textarea id="eventVal" placeholder="请填写事件描述" name="textarea-0" class="uc-a1 ub-f1"></textarea>
                    <div class="btndellzz ub-img umh2 uabs1" onclick="cleartext()">
                    </div>
                </div>
				<div ontouchstart="zy_touch('btn-act')" onclick="openDeptSelect()" class="ub  b-gra  uc-a1 uba c-wh ub-ac umh4 lis ub-pj uinn1-lzz">
                        <li class="uinn3 c-handledep ulev0">
                                                                                处理部门
                        </li>
                        <li id="deptnameli" class="ulev2 c-companyword ulim-lzz">安全监察部</li>
                        <li class="resmore lis-sw ub-img ">
                        </li>
                </div >
				   <!--块容器开始-->
               <div  class="ub ub-ac uc-a1 uba b-gra" >
                  <ul id="pictures" style="overflow:auto;">
					<li  class="c-camerabg ub ub-pc  ub-ac umar5 ub-ver detailpic" onclick="openMenu();" style="float:left;">111111
                        <img id="submitimg" src="css/project/images/img1.png" style="width:100px;height:100%;position:absolute;"/>
                        <div id="cameraStyle" ontouchstart="zy_touch('btn-act')" class="btn ub-img cameralzz"></div>
                    </li>
					 <!--<li class="ub ub-ac umar5 ub-ver detailpic picture" style="float:left;" onclick="preview();">
                        <img id="img1" src="css/images/index.jpg" style="width:100%;height:100%;position:absolute;" onclick="preview(this.src);"/>
						<div class="deleteImg ub-img" style="position:absolute;top:-0.5em;right:-0.5em" onclick="deleteImg(this)"></div>
                  </li>
				  <li class="ub ub-ac umar5 ub-ver detailpic picture" style="float:left;">
                        <img id="img1" src="css/images/report.png" style="width:100%;height:100%;position:absolute;"  onclick="preview(this.src);"/>
						<div class="deleteImg ub-img" style="position:absolute;top:-0.5em;right:-0.5em" onclick="deleteImg(this)"></div>
                  </li>
				  <li class="ub ub-ac umar5 ub-ver detailpic picture" style="float:left;" onclick="preview();">
                        <img id="img1" src="css/images/index-2.png" style="width:100%;height:100%;position:absolute;" onclick="preview(this.src);"/>
						<div class="deleteImg ub-img" style="position:absolute;top:-0.5em;right:-0.5em" onclick="deleteImg(this)"></div>
                  </li>-->
				  </ul>
                </div>
              </div>
           <!--块容器结束-->
            </div>
        <div ontouchstart="zy_touch('c-green-act')" onclick="submitSmsReport()" class="tx-c umar-a-lzz uinn5 c-green t-wh">
            确认提交
        </div>
		
		
    </body>
    <script>
         zy_init();
		//本地相片地址
		var imgurl = "";
		//本地相片地址数组
		var imgUrlArray=[];
		//本地图片标识
		var j=0;
		//上传成功图片地址
		var imgserverpath = "";
		//服务器返回的图片名称和地址
		var returnFiles=[];
		//上传成功图片名称
		var imgservername = "";
		//处理部门ID
		var handleDepId ="21041";
		var eventContent = "";
		var describle="";
		var handleDepVal = "";
		//控制重复提交的标志
		var doubleclick = false;
		//图片总数，每上传一次，总数减一
		var urlArrayLength=0;
		//图片对象
		var imgObjArray=[];
		//上传标识
		var i=0;
		
	  initDeptName();	
	  function initDeptName(){
			if(getStorage("deptNameDefault")){
				$$("deptnameli").innerHTML=getStorage("deptNameDefault");
				handleDepId=getStorage("hddeptid_lzz");
			}
		}
		
		function preview(src){
//             for(var i=0;i<imgUrlArray.length;i++){
//			 	alert("imgUrlArray[i]:"+imgUrlArray[i]+"--src:"+src);
//			 	 if(src==imgUrlArray[i]){
//				 	  var curIndex=i; 
//					  alert(curIndex);
//				 }
//			 }
            uexImageBrowser.open(src);
		}
		
		//全角输入法转半角输入法
		function fullInputConvertHalf(describle){
//			alert("describle---"+describle);
			for(var i=0;i<describle.length;i++){
				if (describle.charCodeAt(i)==12288){//全角空格为12288，半角空格为32 
					eventContent+= String.fromCharCode(describle.charCodeAt(i)-12256);
　　　　             continue;
		     	}
				if (describle.charCodeAt(i)>65280 && describle.charCodeAt(i)<65375)//其他字符半角(33-126)与全角(65281-65374)的对应关系是：均相差65248 
				    eventContent+= String.fromCharCode(describle.charCodeAt(i)-65248);
　　　            else 
                    eventContent+= String.fromCharCode(describle.charCodeAt(i));
	    	}
//			alert("转换半角字母：----"+eventContent);
	}
		
       //提交完成后，删掉当前图片列表
		function removePictures(){
			var pictures = $$("pictures").getElementsByTagName('li');
			for(var i=pictures.length-1;i>=1;i--){
				pictures[i].parentNode.removeChild(pictures[i]);
			}
		}
		
		function openMenu(){
//			eventCount("E1001002","{'拍照':'拍照统计'}");
			if($$("submitimg").src.indexOf("report_content.html")== -1){
	        	var as=new Array(3);
	        	as[0]="拍照";
	        	as[1]="从相册选择";
	        	as[2]="清除";
			}else{
	        	var as=new Array(2);
	        	as[0]="拍照";
	        	as[1]="从相册选择";
			}
        	uexWindow.actionSheet("选择图片","取消",as);
		}
		
		//存放图片的div
		function createImgDiv(id){
		    var appendImgDiv=
			      '<li class="ub ub-ac umar5 ub-ver detailpic picture" style="float:left;">'+
                        '<img id=img'+id+' src="" style="width:100%;height:100%;position:absolute;" onclick="preview(this.src)"/>'+
						'<div class="deleteImg ub-img  " style="position:absolute;top:-0.5em;right:-0.5em" onclick="deleteImg(this)"></div>'+
                  '</li>'
			 $$("pictures").innerHTML+=appendImgDiv;
		}
		
			//删除选中的图片
			function deleteImg(obj){
				var length=imgUrlArray.length-1;
				imgUrlArray.splice(length,1);
				returnFiles.splice(length,1);
				obj.parentElement.outerHTML = "";
			}
        window.uexOnload = function(type){
                            uexWindow.evaluateScript('root', '0', 'open_more()');
            if (!type) {
                uexWindow.setBounce("1");
                uexWindow.showBounceView("0", "#FFF", "0");
                uexWindow.showBounceView("1", "#FFF", "0");
            }
			setStorage("hddeptid_lzz",handleDepId);
			setStorage("hddeptname_lzz","安全监察部");
			//弹出选择相片菜单回调
　　　		uexWindow.cbActionSheet = actionSheetSuccess;
　　　		uexWidgetOne.cbError = function(opCode,errorCode,errorInfo){
　　　			//alert("errorCode:" + errorCode + "\n"+"errorInfo:" + errorInfo);
			}
			
			//相机回调函数
			uexCamera.cbOpen = openCameraCallback;
			uexWidgetOne.cbError= function(inOpId,inErrorCode,inErrorDes){
			}
			//本地相册回调函数
			uexImageBrowser.cbPick = function(opId,dataType,data){
			if(dataType==0){
	                imgUrlArray.push(data);
					var imgIndex=imgUrlArray.length-1;
					createImgDiv(imgIndex);
					document.getElementById("img"+imgIndex).src=data;
//					document.getElementById("img" + imgIndex).onclick = function(){
//						preview(data);
//					}
				}
			}
        }
		function openDeptSelect(){
			eventCount("E1001001","{'部门选择':'部门选择统计'}");
			openwin("selectdept", "selectdept.html", "2");
		}
		function actionSheetSuccess(opId,dataType,data){
			if(data=="0"){
				uexCamera.open('0','50'); 
			}
			if(data=="1"){
				uexImageBrowser.pick();
			}
			if(data=="2"){
				loadingEnd();
				document.getElementById("submitimg").src="";
				imgurl = "";
				imgserverpath = "";
				imgservername = "";
			}
			
		}
        function openCameraCallback(opId,dataType, data){
			if(dataType==0){
	            imgUrlArray.push(data);
				var imgIndex=imgUrlArray.length-1;
	            createImgDiv(imgIndex);
			    document.getElementById("img"+imgIndex).src=data;
//				document.getElementById("img" + imgIndex).onclick = function(){
//						preview(data);
//					}
			}
		}
		function setdeptname(){
			handleDepId = getStorage("hddeptid_lzz");
			$$("deptnameli").innerHTML = getStorage("hddeptname_lzz");
			setStorage("deptNameDefault",$$("deptnameli").innerHTML);
		}
		//提交sms报告
		var uploadHttp = uploadUrl+"FileService/Ability/file/fileAction!getUploadInfo.action";
		function submitSmsReport(){
			eventCount("E1001003","{'确认提交':'确认提交统计'}");
		    describle = $$("eventVal").value.replace(/[\r\n]/g,"");
			handleDepVal = handleDepId;
			if(describle == ""){
				loadingStart("请填写事件描述",1000);
				return;
			}
			if(handleDepVal == ""){
				loadingStart("请选择处理部门",1000);
				return;
			}
			if(!doubleclick){
				doubleclick = true;
//				if ($$("submitimg").src.indexOf("report_content.html")== -1) {
               	 urlArrayLength=imgUrlArray.length;
//				 alert("urlArrayLength---"+urlArrayLength);
//                fullInputConvertHalf(describle);
                if(urlArrayLength>0){
					postSmsReport();
				}else{
					postReportData();
				}
				
			}
		} //TODO  TEST
      
		function postSmsReport(){
			  	var milliSeconds = new Date().getTime();
			  	var jsonstr = "{\"test\":\"value\"}";
				var imgObj=new Object();
				imgObj.imgName=imgUrlArray[urlArrayLength - 1];
				imgObjArray[i]=imgObj;
			  	$uploadFile(uploadHttp, imgUrlArray[urlArrayLength - 1], jsonstr, "smspic" + milliSeconds);
		}  //TODO  TEST--jsonstr,smspic ??
		
		function postReportData(){
			var nonameflg = typeof(getStorage("nonamesubmit"))=='undefined'?"true":getStorage("nonamesubmit");
			if(nonameflg == "false"){
				var userName = typeof(getStorage("personname"))=='undefined'?"":getStorage("personname");
				var mobilephoneNum = typeof(getStorage("personphone"))=='undefined'?"":getStorage("personphone");
				var email = typeof(getStorage("personemail"))=='undefined'?"":getStorage("personemail");
			}else{
				var userName = "";
				var mobilephoneNum = "";
				var email = "";
			}
			var postdata=[];
			var activity='';
//			alert(userName);
//			alert("attachments.length--"+returnFiles.length);
			  var returnFilesJson=JSON.stringify(returnFiles);   
//			alert(attachmentsJson.substr(0,100));
//			console.log(returnFilesJson);
//             alert(handleDepVal);
			if(returnFiles.length>0){								                activity='{"description":\"'+describle+'\","unit":'+parseInt(handleDepVal)+',"reporterPhone":\"'+mobilephoneNum+'\","email":\"'+email+'\","deviceId":\"'+getStorage("deviceID")+'\","mtype":"mobile","source":"app","userName":\"'+userName+'\","userCode":"","attachments":'+returnFilesJson+'}';
			}else{
				activity='{"description":"'+describle+'","unit":'+parseInt(handleDepVal)+',"reporterPhone":"'+mobilephoneNum+'","email":"'+email+'","deviceId":\"'+getStorage("deviceID")+'\","mtype":"mobile","source":"sms","userName":"'+userName+'","userCode":"","attachments":[]}';
			}
			  postdata=[
			  {"key":"nologin","type":"0","value":"Y"},
			  {"key":"method","type":"0","value":"submitEmReport"},
			  {"key":"activity","type":"0","value":activity}
			];
//			console.log("postDataUrl--"+postDataUrl);
//			console.log("postdata--"+JSON.stringify(postdata));
//            alert(("postdata--"+JSON.stringify(postdata)));
//            alert(postdata.substr(0,50));
            loadingStart("提交中...","");
			$.getJSON(postDataUrl,postReportDataback,"json",function(err){uexWindow.toast('0', '5', '系统调用错误', 1000);},"POST",postdata);
		} //TODO  TEST  ??

		function postReportDataback(json){
//					alert(JSON.stringify(json));
					loadingEnd();
					doubleclick = false;
					var obj = json;
					if(obj.success){
						removePictures();
						$$("eventVal").value = "";
						$$("submitimg").style.display='none';
						$$("cameraStyle").style.display='block';
						document.getElementById("submitimg").src="";
						imgserverpath = "";
						imgservername = "";
						loadingStart("提交成功",1500);
						imgUrlArray.length=0;
						returnFiles.length=0;
					}else{
							loadingStart("提交失败",1000);
						}
				} //TODO TEST
				
		function cleartext(){ //TODO TEST
			$$("eventVal").value = "";
		}
		function getNameFlg(){
			uexWindow.evaluatePopoverScript('personcenter','personcenter_content','gethideNameflg()');
		}
        //上传图片
		function $uploadFile(upload_url, upload_file, json_str, fileid_str){
		getUploadInfor(upload_url, upload_file, json_str, fileid_str);
		return;
		
		upload_url = uploadUrl+'FileService/Ability/file/fileAction!getUploadInfo.action';
		
		uexUploaderMgr.onStatus = function(opId,fileSize, percent,serverPath,status){
			switch (status) {
				case 0 :
					uexWindow.toast('0','5','上传'+percent+'%','');
					break;
				case 1 :
					uexWindow.closeToast();
					uexUploaderMgr.closeUploader(opCode);
					break;
				case 2 :
					uexWindow.closeToast();
					loadingStart("上传失败",1000);
					uexUploaderMgr.closeUploader(opCode);
					return;
			}
		};
		uexUploaderMgr.cbCreateUploader = function(opCode, dataType, data) {
			if (data == 0) {
				uexUploaderMgr.uploadFile(opCode, upload_file, fileid_str, '2');
			} else {
				uexUploaderMgr.closeUploader(opCode);
			}
		};
		uexUploaderMgr.createUploader(that.opId, upload_url);
	}
	
	function getUploadInfor(upload_url, upload_file, json_str, fileid_str){
		var opid = parseInt(Math.random()*1000);
		var ms = new Date().getTime();
		
		fileUpload(upload_url, upload_file, json_str, fileid_str, ms+'.jpg');
		return;
		
		uexXmlHttpMgr.onData = function (_opid, status, result){
			if(status==0) return;
			else if(status==-1) 
			loadingStart("上传失败",1000);
			uexXmlHttpMgr.close(_opid);
			
			if(status==1) fileUpload(upload_url, upload_file, json_str, fileid_str, ms+'.jpg');
		}
		uexXmlHttpMgr.open(opid, "GET", upload_url, 30000);
		var json_header = {
			"fileId" : fileid_str,
			"fileName" : ms + '.jpg'
		};
		var sss = JSON.stringify(json_header);
		uexXmlHttpMgr.setHeaders(opid, sss);
		uexXmlHttpMgr.send(opid);
	}
	
	function fileUpload(upload_url, upload_file, json_str, fileid_str, file_name){
		var opid = parseInt(Math.random()*1000);
		var ms = new Date().getTime();
		var url = uploadUrl+'FileService/Ability/file/fileAction!uploadFile.action';
		
		uexXmlHttpMgr.onData = function (_opid, status, result){
			if(status==0) return;
			else if (status == -1) {
//				loadingStart("上传失败",1000);
			   loadingStart(imgObjArray[i].imgName+"上传失败,请重新上传",2000);
			   doubleclick=false;
			}
			else if (status == 1){
				i++;
				var doc = createDoc(result);
				var message = getNodeValue(doc, "desc", 0);
//				console.log(message);
				imgservername = message.substring(message.indexOf("fileName=")+9,message.indexOf("fileInfo=")).trim();
				imgserverpath = message.substring(message.indexOf("fileAbsoluteName=")+17,message.indexOf("isComplete=")).trim();
               var path="http://mp1.ceair.com/Image/servlet/ImageServlet?path="+ base64.encode(imgserverpath);
			    returnFiles.push({name:imgservername,path:path,size:""});
//				console.log("name--"+imgservername+"---path--"+path);
				urlArrayLength=urlArrayLength-1;
				imgUrlArray.splice(urlArrayLength,1);
				if(urlArrayLength>0){
					postSmsReport();
				}else{
					postReportData();
				}
			}
			uexXmlHttpMgr.close(_opid);
		}
		uexXmlHttpMgr.open(opid, "POST", url, 300*1000);
		var json_header = {
			"fileId" : fileid_str,
			"fileName" : file_name,
			"isFirst" : "1",
			"fileInfo" : json_str
		};
		var sss = JSON.stringify(json_header);
		try {
		uexXmlHttpMgr.setHeaders(opid, sss);
		
			uexXmlHttpMgr.setInputStream(opid, upload_file);
		}catch(e){
		}
		uexXmlHttpMgr.send(opid);
	}	
	
    </script>
</html>
